public class pivotIndex {
    public int pivotIndex(int[] nums) {
        //找数组的中心下标这个不就是对半分，计算数组总和后再找出一半即可
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        //sumRight = Arrays.stream(nums).sum()流计算真是优雅
        int leftsum = 0;
        for (int i = 0; i < nums.length; i++) {
            if (leftsum == sum - leftsum - nums[i]) {
                return i;
            }
            leftsum += nums[i];
        }
        return -1;
    }
}
